"""
!/usr/bin/env python
-*- coding: utf-8 -*-
@Author  : MarkJia
@Site    : 
@File    : 17、自动化关键数据记录.py
"""

# =========================== 自动化关键信息记录 ==============================================
"""
1. 行为日志记录 ： 1. 记录代码的执行记录，方便复现场景， 2. 可作为 bug 记录
    日志配置
    脚本日志级别
        debug 记录步骤信息
        info 记录关键信息，比如断言等
        
2. 步骤截图记录 ： 
    1. 断言失败或成功截图  
    2. 异常截图达到丰富的测试报告  
    3， 可作为 bug 依据
    
3. page source 记录 ： 
    协助排查报错时，元素时当时是否存在页面上  - no such element

"""

import logging
from selenium import webdriver
from selenium.webdriver.common.by import By


# 日志配置
def get_logger():
    # 创建 logger 实例
    logger = logging.getLogger('simple_example')
    # 设置日志级别
    logger.setLevel(logging.DEBUG)
    # 流处理器
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    # 日志打印格式
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    # 添加格式设置
    ch.setFormatter(formatter)
    # 添加日志配置
    logger.addHandler(ch)

    return logger


logger = get_logger()


# UI 脚本  ->  搜狗首页
class TestDataRecord:

    def setup_class(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(3)

    def teardown_class(self):
        self.driver.quit()

    # ================================= 添加日志 ========================================
    def test_log_data_record(self):
        search_content = '霍格沃兹测试开发'
        self.driver.get('https://www.sogou.com/')
        # 输入 霍格沃兹开发
        self.driver.find_element(By.CSS_SELECTOR, '#query').send_keys(search_content)
        # 2022-04-30 23:08:02,059 - simple_example - DEBUG - 搜索的内容为:霍格沃兹测试开发
        logger.debug(f'搜索的内容为:{search_content}')
        # 点击搜索按钮
        self.driver.find_element(By.CSS_SELECTOR, "#stb").click()
        # 实际结果
        search_res = self.driver.find_element(By.CSS_SELECTOR, 'em').text
        # 2022-04-30 23:08:02,814 - simple_example - INFO - 获取到的实际结果为霍格沃兹测试开发,预期结果为霍格沃兹测试开发
        logger.info(f'获取到的实际结果为{search_res},预期结果为{search_content}')
        # 断言 ： 实际结果 == 预期结果
        assert search_res == search_content

    # ==============================================  步骤截图记录  ===================================================
    # ==================   save_screenshot(截图路径 + 名称) -> driver.save_screenshot('./images/search1.png')  =======================

    def test_screen_shot_data_record(self):
        search_content = '霍格沃兹测试开发'
        self.driver.get('https://www.sogou.com/')
        # 输入 霍格沃兹开发
        self.driver.find_element(By.CSS_SELECTOR, '#query').send_keys(search_content)
        # 2022-04-30 23:08:02,059 - simple_example - DEBUG - 搜索的内容为:霍格沃兹测试开发
        logger.debug(f'搜索的内容为:{search_content}')
        # 点击搜索按钮
        self.driver.find_element(By.CSS_SELECTOR, "#stb").click()
        # 实际结果
        search_res = self.driver.find_element(By.CSS_SELECTOR, 'em').text
        # 2022-04-30 23:08:02,814 - simple_example - INFO - 获取到的实际结果为霍格沃兹测试开发,预期结果为霍格沃兹测试开发
        logger.info(f'获取到的实际结果为{search_res},预期结果为{search_content}')
        # ============================   在断言之前，添加截图  -> 截图记录  ========================================
        self.driver.save_screenshot('search_res.png')
        # self.driver.get_screenshot_as_file('search1_res.png')
        # 断言 ： 实际结果 == 预期结果
        assert search_res == search_content

    # ===========================================    page_souce   ======================================================
    def test_page_source(self):
        # 现象 ： 产生了 no such element 的错误。
        # 解决方案：在报错的代码行之前打印 page_source，确认定位的元素没有问题
        search_content = '霍格沃兹测试开发'
        self.driver.get('https://www.sogou.com/')
        with open('1.html', 'w', encoding='utf-8') as f:
            f.write(self.driver.page_source)
        # 输入 霍格沃兹开发
        self.driver.find_element(By.CSS_SELECTOR, '#query888888').send_keys(search_content)
        # 获取 page_source
        # <html lang="cn"><head><meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no"><script>window._speedMark = new Date();  window.lead_ip = '111.18.94.163';window.now = 1651332523119;</script><script type="text/javascript">/*file=static/js/resourceErrorReport.js*/!function(department){var n=(new Date).getTime(),r=department.location.protocol;function c(e,t){var o=(new Date).getTime()-n;(new Image).src=["//pb.sogou.com/pv.gif?uigs_productid=wapapp&type=resource-error&stype=",e,"&timestamp=",o,"&protocol=",r,"&host=",encodeURIComponent(department.location.host),"&path=",encodeURIComponent(department.location.pathname),"&resource=",encodeURIComponent(t)].join("")}function e(e){if((e=e||department.event)&&"error"===e.type){var t=e.srcElement?e.srcElement:e.target;if(t){var o,n,r=t.tagName;"LINK"===r?(n="css",(o=t.getAttribute("href"))&&o.match(/\.css($|\?)/)&&c(n,o)):"SCRIPT"===r&&(n="js",(o=t.getAttribute("src"))&&o.match(/\.js($|\?)/)&&c(n,o))}}}r&&(r=r.substring(0,r.length-1)),department.addEventListener?department.addEventListener("error",e,!0):department.attachEvent&&department.attachEvent("onerror",e)}(window);</script><meta charset="utf-8"><link rel="dns-prefetch" href="//img01.sogoucdn.com"><link rel="dns-prefetch" href="//img02.sogoucdn.com"><link rel="dns-prefetch" href="//img03.sogoucdn.com"><link rel="dns-prefetch" href="//img04.sogoucdn.com"><link rel="dns-prefetch" href="//dlweb.sogoucdn.com"><title>搜狗搜索引擎 - 上网从搜狗开始</title><link rel="shortcut icon" href="/images/logo/new/favicon.ico?v=4" type="images/x-icon"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="搜狗搜索"><meta name="keywords" content="搜狗搜索,网页搜索,微信搜索,视频搜索,图片搜索,音乐搜索,新闻搜索,软件搜索,问答搜索,百科搜索,购物搜索"><meta name="description" content="搜狗搜索是全球第三代互动式搜索引擎，支持微信公众号和文章搜索、知乎搜索、英文搜索及翻译等，通过自主研发的人工智能算法为用户提供专业、精准、便捷的搜索服务。"><link rel="stylesheet" type="text/css" href="//dlweb.sogoucdn.com/pcsearch/web/index/css/index_style_39e6e10.css"><style>.wrapper .suggestion{border:1px solid #e8e8e8;width:653px;-moz-box-shadow:0 1px 8px rgba(0,0,0,.1);-webkit-box-shadow:0 1px 8px rgba(0,0,0,.1);box-shadow:0 1px 8px rgba(0,0,0,.1);border-top-left-radius:0;border-top-right-radius:0;border-bottom-right-radius:2px;border-bottom-left-radius:2px;top:43px}.wrapper .suglist{width:206px}.wrapper .suglist .keyword{color:#7a77c8}.big-scn .suggestion{width:820px}.big-scn .suglist{width:236px}.wrapper .suglist{padding:4px 0}input[type=text]::-ms-clear{display:none}</style><!-- indexSnippetToHeader start -->  <!-- indexSnippetToHeader end --><link rel="stylesheet" type="text/css" href="/sug/css/suggestion.min.v.5.css"><link rel="stylesheet" type="text/css" href="/web/css/yuyin.v1.0.1.css"></head><body color-style="white" style=""><div class="wrapper " id="wrap"><div class="header"> <div class="top-nav"><ul><li class="cur"><span>网页</span></li><li><department onclick="st(this,'73141200','weixin')" href="http://weixin.sogou.com/" uigs-id="nav_weixin" id="weixinch">微信</department></li><li><department onclick="st(this,'40051200','zhihu')" href="http://zhihu.sogou.com/" uigs-id="nav_zhihu" id="zhihu">知乎</department></li><li><department onclick="st(this,'40030500','pic')" href="http://pic.sogou.com" uigs-id="nav_pic" id="pic">图片</department></li><li><department onclick="st(this,'40030600','video')" href="https://v.sogou.com/" uigs-id="nav_v" id="video">视频</department></li><li><department href="http://mingyi.sogou.com?fr=common_index_nav" uigs-id="nav_mingyi" id="mingyi" onclick="st(this,'','myingyi')">医疗</department></li><li><department href="http://hanyu.sogou.com?fr=pcweb_index_nav" uigs-id="nav_hanyu" id="hanyu" onclick="st(this,'','hanyu')">汉语</department></li><li><department href="http://english.sogou.com?fr=pcweb_index_nav" uigs-id="nav_overseas" id="overseas" onclick="st(this,'','overseas')">英文</department></li><li><department onclick="st(this,'web2ww','wenwen')" href="https://wenwen.sogou.com/?ch=websearch" uigs-id="nav_wenwen" id="index_more_wenwen">问问</department></li><li><department href="http://scholar.sogou.com?fr=common_index_nav" uigs-id="nav_scholar" id="scholar" onclick="st(this,'','scholar')">学术</department></li><li><department onclick="st(this,'40031000')" href="http://map.sogou.com" uigs-id="nav_map" id="map">地图</department></li><li class="show-more"><department href="javascript:void(0);" id="more-product">更多<i class="m-arr"></i></department><div class="pos-more" id="products-box" style="top:40px"><span class="ico-san"></span><department onclick="st(this,'40031500')" href="http://gouwu.sogou.com/" uigs-id="nav_gouwu" id="index_more_gouwu">购物</department><department onclick="st(this,'40051203')" href="http://baike.sogou.com/Home.v" uigs-id="nav_baike" id="index_more_baike">百科</department><department onclick="st(this)" href="http://zhishi.sogou.com" uigs-id="nav_zhishi" id="index_more_zhishi">知识</department><department onclick="st(this,'40051205')" href="http://as.sogou.com/" uigs-id="nav_app" id="index_more_appli">应用</department><department onclick="st(this,'40051205','fanyi')" href="http://fanyi.sogou.com?fr=common_index_nav_pc" uigs-id="nav_fanyi" id="index_more_fanyi">翻译</department>  <department href="https://baike.sogou.com/kexue/home.htm" uigs-id="nav_science" id="science">科学</department><span class="all"><department onclick="st(this,'40051206')" href="http://www.sogou.com/docs/more.htm?v=1" uigs-id="nav_all" target="_blank">全部</department></span></div></li></ul></div><div class="user-box">  <department href="javascript:void(0)" id="cniil_wza" style="float:left;text-decoration:none;color:#000;opacity:.75;padding-right:20px;margin-right:20px;border-right:1px solid #e7e7e7;line-height:14px;position:relative;top:5px">无障碍</department>  <div class="local-weather" id="local-weather"><div class="wea-box" id="cur-weather" style="display: block;"><span class="c6">陕西	西安</span><i><img src="/web/index/images/weather/multicolor/yin.png" width="16" height="16" title="阴" alt="阴"></i><span class="c6">14°</span><span class="pj-w "> </span></div>  <div class="pos-more" id="detail-weather" style="top:40px;left:-80px"><span class="ico-san"></span><div class="weather-pos"><div class="riqi">4月30日（周六）<department href="javascript:void(0);" uigs-id="weather_city" id="weather-city-btn" class="adree">更换城市<i class="m-arr"></i></department><div class="shaixuan"><div class="part1"><select name="" id="weather-province"></select></div><div class="part1"><select name="" id="weather-city"></select></div><div class="part2"><department href="javascript:void(0);" uigs-id="weather_change" id="weather-change">更换</department></div></div></div><department href="/web?ie=utf8&amp;from=index_weather&amp;query=%E9%99%95%E8%A5%BF%09%E8%A5%BF%E5%AE%89%E5%A4%A9%E6%B0%94" uigs-id="weather_days" class="wd-info"><div class="s1">14°<span class="you "> </span></div><div class="s2"><p class="p1">阴</p><p class="p1">9/19°</p><p class="p2">西南风</p></div></department><ul class="other-day"><li><department href="/web?ie=utf8&amp;from=index_weather&amp;query=%E9%99%95%E8%A5%BF%09%E8%A5%BF%E5%AE%89%E5%A4%A9%E6%B0%94" title="多云转晴" uigs-id="weather_days"><p class="day">明天</p><p class="ico-tq"><img src="/web/index/images/weather/multicolor/duoyun.png" width="28" height="28" alt="多云转晴"></p><p class="wd">10/22°</p></department></li><li><department href="/web?ie=utf8&amp;from=index_weather&amp;query=%E9%99%95%E8%A5%BF%09%E8%A5%BF%E5%AE%89%E5%A4%A9%E6%B0%94" title="晴" uigs-id="weather_days"><p class="day">后天</p><p class="ico-tq"><img src="/web/index/images/weather/multicolor/qing.png" width="28" height="28" alt="晴"></p><p class="wd">10/25°</p></department></li><li><department href="/web?ie=utf8&amp;from=index_weather&amp;query=%E9%99%95%E8%A5%BF%09%E8%A5%BF%E5%AE%89%E5%A4%A9%E6%B0%94" title="晴" uigs-id="weather_days"><p class="day">周二</p><p class="ico-tq"><img src="/web/index/images/weather/multicolor/qing.png" width="28" height="28" alt="晴"></p><p class="wd">11/27°</p></department></li></ul></div></div>  </div><span class="line" id="user-box-line" style=""></span><div class="user-enter">  <department href="javascript:void(0);" class="enter" id="loginBtn">登录</department>  </div></div></div><div class="content" id="content"><div class="pos-header" id="top-float-bar"><div class="part-one"></div><div class="part-two" id="card-tab-layer"><div class="c-top" id="top-card-tab"></div></div></div><div class="logo2" id="logo-s"><span></span></div><div class="logo" id="logo-l"><span></span></div> <div class="search-box querybox-focus" id="search-box"><form action="/web" name="sf" id="sf"><span class="sec-input-box"><input type="text" class="sec-input active" name="query" id="query" maxlength="100" len="80" autocomplete="off"></span><span class="enter-input"><input type="submit" value="搜狗搜索" id="stb"></span><input type="hidden" name="_asf" value="www.sogou.com"> <input type="hidden" name="_ast"> <input type="hidden" name="w" value="01019900"> <input type="hidden" name="p" value="40040100"> <input type="hidden" name="ie" value="utf8">  <input type="hidden" name="from" value="index-nologin">  <input type="hidden" name="s_from" value="index"><div class="keywords-tips" id="keywordsTips" style="display:none"><i></i><p>“<strong id="keywordsTipsStrong">369</strong>”后面的文字被忽略，搜狗的查询限制在40个汉字以内。</p></div></form><department href="javascript:void(0);" uigs-id="voice_btn" id="voice-btn" class="input-voice" title="语音搜索"><i></i></department></div>  </div><div class="card-box" id="card-box" style="display:none"><div class="card-box2" id="card-box2"><div class="c-top" id="card-tab-box"><department href="javascript:void(0);" uigs-id="settings_close-card" id="close-card" class="shezhi"></department></div><div class="c-main" id="card-content"><div style="display: none;"><div class="c-main-left"><ul class="news-list" id="news-list"><li style="padding:78px 0;border:none;"></li></ul><div class="loading-box" id="no-more" style="display: none;">没有更多内容了~</div><div class="loading-box" id="loading"><i class="loading-gif"></i>正在加载...</div><div class="loading-box" id="loading-fail"><i class="loading-err"></i>加载失败，<department href="javascript:void(0);" id="reload">点击重新加载</department></div></div><div class="c-main-right js-content-right" id="card-news-right" style="display: none;"><div class="r-tit"><department href="http://top.sogou.com/?fr=mhd_card" uigs-id="news_hot-title" target="_blank">实时热点&nbsp;<span>&gt;</span></department></div><ul class="hot-list" id="hot-list"></ul><div class="right-ewm"> <div class="r-tit">下载搜狗搜索APP</div><div class="ewm-box"><div class="ewm"><img src="/web/index/images/erweima2.png" alt=""></div><div class="ewm-txt"><p>搜狗搜索APP</p><span>搜你所想</span></div></div></div></div></div><div style="display: none;"><div class="dh-tit">热门推荐</div><ul class="dh-list"><li><department href="http://www.weibo.com" uigs-id="card_nav-0-0" target="_blank" title="新浪微博"><img class="js-site-logo" data-src="/web/index/images/site_logo/h_weibo.png" src="/web/index/images/loading.gif" width="16" height="16" alt="新浪微博">新浪微博</department></li><li><department href="http://www.taobao.com" uigs-id="card_nav-0-1" target="_blank" title="淘宝网"><img class="js-site-logo" data-src="/web/index/images/site_logo/h_taobao.png" src="/web/index/images/loading.gif" width="16" height="16" alt="淘宝网">淘宝网</department></li><li><department href="http://www.iqiyi.com" uigs-id="card_nav-0-2" target="_blank" title="爱奇艺"><img class="js-site-logo" data-src="/web/index/images/site_logo/h_iqiyi.png" src="/web/index/images/loading.gif" width="16" height="16" alt="爱奇艺">爱奇艺</department></li><li><department href="http://www.4399.com" uigs-id="card_nav-0-3" target="_blank" title="4399小游戏"><img class="js-site-logo" data-src="/web/index/images/site_logo/h_4399.png" src="/web/index/images/loading.gif" width="16" height="16" alt="4399小游戏">4399小游戏</department></li><li><department href="http://weixin.qq.com" uigs-id="card_nav-0-4" target="_blank" title="微信"><img class="js-site-logo" data-src="/web/index/images/site_logo/h_weixin.png" src="/web/index/images/loading.gif" width="16" height="16" alt="微信">微信</department></li><li><department href="http://www.sohu.com" uigs-id="card_nav-0-5" target="_blank" title="搜狐网"><img class="js-site-logo" data-src="/web/index/images/site_logo/h_sohu.png" src="/web/index/images/loading.gif" width="16" height="16" alt="搜狐网">搜狐网</department></li></ul><div class="dh-tit">视频娱乐</div><ul class="dh-list"><li><department href="http://v.qq.com" uigs-id="card_nav-1-0" target="_blank" title="腾讯视频"><img class="js-site-logo" data-src="/web/index/images/site_logo/v_qq.png" src="/web/index/images/loading.gif" width="16" height="16" alt="腾讯视频">腾讯视频</department></li><li><department href="http://tv.sohu.com" uigs-id="card_nav-1-1" target="_blank" title="搜狐视频"><img class="js-site-logo" data-src="/web/index/images/site_logo/v_sohu.png" src="/web/index/images/loading.gif" width="16" height="16" alt="搜狐视频">搜狐视频</department></li><li><department href="http://www.bilibili.com" uigs-id="card_nav-1-2" target="_blank" title="哔哩哔哩"><img class="js-site-logo" data-src="/web/index/images/site_logo/v_bilibili.png" src="/web/index/images/loading.gif" width="16" height="16" alt="哔哩哔哩">哔哩哔哩</department></li><li><department href="http://www.youku.com" uigs-id="card_nav-1-3" target="_blank" title="优酷视频"><img class="js-site-logo" data-src="/web/index/images/site_logo/v_youku.png" src="/web/index/images/loading.gif" width="16" height="16" alt="优酷视频">优酷视频</department></li><li><department href="http://www.tudou.com" uigs-id="card_nav-1-4" target="_blank" title="土豆视频"><img class="js-site-logo" data-src="/web/index/images/site_logo/v_tudou.png" src="/web/index/images/loading.gif" width="16" height="16" alt="土豆视频">土豆视频</department></li></ul><div class="dh-tit">新闻资讯</div><ul class="dh-list"><li><department href="http://news.sina.com.cn" uigs-id="card_nav-2-0" target="_blank" title="新浪新闻"><img class="js-site-logo" data-src="/web/index/images/site_logo/n_sina.png" src="/web/index/images/loading.gif" width="16" height="16" alt="新浪新闻">新浪新闻</department></li><li><department href="http://news.163.com" uigs-id="card_nav-2-1" target="_blank" title="网易新闻"><img class="js-site-logo" data-src="/web/index/images/site_logo/n_163.png" src="/web/index/images/loading.gif" width="16" height="16" alt="网易新闻">网易新闻</department></li><li><department href="http://news.sohu.com" uigs-id="card_nav-2-2" target="_blank" title="搜狐新闻"><img class="js-site-logo" data-src="/web/index/images/site_logo/n_sohu.png" src="/web/index/images/loading.gif" width="16" height="16" alt="搜狐新闻">搜狐新闻</department></li><li><department href="http://news.qq.com" uigs-id="card_nav-2-3" target="_blank" title="腾讯新闻"><img class="js-site-logo" data-src="/web/index/images/site_logo/n_qq.png" src="/web/index/images/loading.gif" width="16" height="16" alt="腾讯新闻">腾讯新闻</department></li><li><department href="http://news.ifeng.com" uigs-id="card_nav-2-4" target="_blank" title="凤凰资讯"><img class="js-site-logo" data-src="/web/index/images/site_logo/n_ifeng.png" src="/web/index/images/loading.gif" width="16" height="16" alt="凤凰资讯">凤凰资讯</department></li><li><department href="http://www.xinhuanet.com" uigs-id="card_nav-2-5" target="_blank" title="新华网"><img class="js-site-logo" data-src="/web/index/images/site_logo/n_xinhua.png" src="/web/index/images/loading.gif" width="16" height="16" alt="新华网">新华网</department></li></ul><div class="dh-tit">在线音乐</div><ul class="dh-list"><li><department href="http://music.163.com" uigs-id="card_nav-3-0" target="_blank" title="网易云音乐"><img class="js-site-logo" data-src="/web/index/images/site_logo/m_163.png" src="/web/index/images/loading.gif" width="16" height="16" alt="网易云音乐">网易云音乐</department></li><li><department href="http://y.qq.com" uigs-id="card_nav-3-1" target="_blank" title="QQ音乐"><img class="js-site-logo" data-src="/web/index/images/site_logo/m_qq.png" src="/web/index/images/loading.gif" width="16" height="16" alt="QQ音乐">QQ音乐</department></li><li><department href="http://www.xiami.com" uigs-id="card_nav-3-2" target="_blank" title="虾米音乐"><img class="js-site-logo" data-src="/web/index/images/site_logo/m_xiami.png" src="/web/index/images/loading.gif" width="16" height="16" alt="虾米音乐">虾米音乐</department></li><li><department href="http://douban.fm" uigs-id="card_nav-3-3" target="_blank" title="豆瓣电台"><img class="js-site-logo" data-src="/web/index/images/site_logo/m_FM.png" src="/web/index/images/loading.gif" width="16" height="16" alt="豆瓣电台">豆瓣电台</department></li><li><department href="http://www.yinyuetai.com" uigs-id="card_nav-3-4" target="_blank" title="音悦台"><img class="js-site-logo" data-src="/web/index/images/site_logo/m_yinyuetai.png" src="/web/index/images/loading.gif" width="16" height="16" alt="音悦台">音悦台</department></li></ul><div class="dh-tit">购物大全</div><ul class="dh-list"><li><department href="http://www.jd.com" uigs-id="card_nav-4-0" target="_blank" title="京东"><img class="js-site-logo" data-src="/web/index/images/site_logo/s_jd.png" src="/web/index/images/loading.gif" width="16" height="16" alt="京东">京东</department></li><li><department href="http://www.jumei.com" uigs-id="card_nav-4-1" target="_blank" title="聚美优品"><img class="js-site-logo" data-src="/web/index/images/site_logo/s_jumei.png" src="/web/index/images/loading.gif" width="16" height="16" alt="聚美优品">聚美优品</department></li><li><department href="http://www.vip.com" uigs-id="card_nav-4-2" target="_blank" title="唯品会"><img class="js-site-logo" data-src="/web/index/images/site_logo/s_vip.png" src="/web/index/images/loading.gif" width="16" height="16" alt="唯品会">唯品会</department></li><li><department href="http://www.yhd.com" uigs-id="card_nav-4-3" target="_blank" title="1号店"><img class="js-site-logo" data-src="/web/index/images/site_logo/s_yhd.png" src="/web/index/images/loading.gif" width="16" height="16" alt="1号店">1号店</department></li><li><department href="http://www.suning.com" uigs-id="card_nav-4-4" target="_blank" title="苏宁易购"><img class="js-site-logo" data-src="/web/index/images/site_logo/s_suning.png" src="/web/index/images/loading.gif" width="16" height="16" alt="苏宁易购">苏宁易购</department></li><li><department href="http://www.tmall.com" uigs-id="card_nav-4-5" target="_blank" title="天猫"><img class="js-site-logo" data-src="/web/index/images/site_logo/s_tmall.png" src="/web/index/images/loading.gif" width="16" height="16" alt="天猫">天猫</department></li></ul><div class="dh-tit">生活旅游</div><ul class="dh-list"><li><department href="http://www.12306.cn" uigs-id="card_nav-5-0" target="_blank" title="12306"><img class="js-site-logo" data-src="/web/index/images/site_logo/l_12306.png" src="/web/index/images/loading.gif" width="16" height="16" alt="12306">12306</department></li><li><department href="http://www.qunar.com" uigs-id="card_nav-5-1" target="_blank" title="去哪儿"><img class="js-site-logo" data-src="/web/index/images/site_logo/l_qunar.png" src="/web/index/images/loading.gif" width="16" height="16" alt="去哪儿">去哪儿</department></li><li><department href="http://www.ctrip.com" uigs-id="card_nav-5-2" target="_blank" title="携程"><img class="js-site-logo" data-src="/web/index/images/site_logo/l_ctrip.png" src="/web/index/images/loading.gif" width="16" height="16" alt="携程">携程</department></li><li><department href="http://www.tuniu.com" uigs-id="card_nav-5-3" target="_blank" title="途牛"><img class="js-site-logo" data-src="/web/index/images/site_logo/l_tuniu.png" src="/web/index/images/loading.gif" width="16" height="16" alt="途牛">途牛</department></li><li><department href="http://www.dianping.com" uigs-id="card_nav-5-4" target="_blank" title="大众点评"><img class="js-site-logo" data-src="/web/index/images/site_logo/l_dianping.png" src="/web/index/images/loading.gif" width="16" height="16" alt="大众点评">大众点评</department></li><li><department href="http://www.fang.com" uigs-id="card_nav-5-5" target="_blank" title="搜房"><img class="js-site-logo" data-src="/web/index/images/site_logo/l_fang.png" src="/web/index/images/loading.gif" width="16" height="16" alt="搜房">搜房</department></li><li><department href="http://www.58.com" uigs-id="card_nav-5-6" target="_blank" title="58同城"><img class="js-site-logo" data-src="/web/index/images/site_logo/l_58.png" src="/web/index/images/loading.gif" width="16" height="16" alt="58同城">58同城</department></li><li><department href="http://www.lvmama.com/" uigs-id="card_nav-5-7" target="_blank" title="驴妈妈"><img class="js-site-logo" data-src="/web/index/images/site_logo/l_lvmama.png" src="/web/index/images/loading.gif" width="16" height="16" alt="驴妈妈">驴妈妈</department></li></ul></div></div></div></div><div class="loog-more" id="scroll-more" style="display:none"><department href="javascript:void(0);" uigs-id="scroll-more">滚动查看更多<br><span class="ico_san"></span></department></div><div class="ft" id="footer" style="display:none"><department href="http://b.sogou.com/" target="_blank" uigs-id="footer_tuiguang">企业推广</department><span class="line"></span><department href="http://www.sogou.com/docs/terms.htm?v=1" target="_blank" uigs-id="footer_disclaimer">免责声明</department><span class="line"></span><department href="http://fankui.help.sogou.com/index.php/web/web/index/type/4" target="_blank" uigs-id="footer_feedback">意见反馈及投诉</department><span class="line"></span><department href="http://corp.sogou.com/private.html" target="_blank" uigs-id="footer_private">隐私政策</department><br><span class="g">药品医疗器械网络信息服务备案：（京）网药械信息备字（2021）第00047号</span>&nbsp;/&nbsp;<span class="g">互联网药品信息服务资格证书(非经营性)：(京)-非经营性-2018-0311</span><br>©&nbsp;2004-2022&nbsp;Sogou.com&nbsp;/&nbsp;<department href="http://www.12377.cn" class="g" target="_blank">网上有害信息举报专区</department>&nbsp;/&nbsp;<span class="g">京网文(2019)6117-724号</span>&nbsp;/&nbsp;<department class="g" href="https://beian.miit.gov.cn/" target="_blank">京ICP证050897号</department>&nbsp;/&nbsp;<department class="g" href="https://beian.miit.gov.cn/" target="_blank">京ICP备11001839号-1</department>&nbsp;/&nbsp;<department href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11000002000025" class="ba" target="_blank">京公网安备11000002000025号</department></div>  <div class="ft-v1" id="QRcode-footer" style="padding-bottom:28px"><div class="ft-info"><department uigs-id="mid_pinyin" href="http://pinyin.sogou.com/" target="_blank"><i class="i1"></i>搜狗输入法</department><span class="line"></span><department uigs-id="mid_liulanqi" href="http://ie.sogou.com/" target="_blank"><i class="i2"></i>浏览器</department><span class="line"></span><department uigs-id="mid_daohang" href="http://123.sogou.com/" target="_blank"><i class="i3"></i>网址导航</department><br><department href="http://b.sogou.com/" target="_blank" class="g">企业推广</department>&nbsp;-&nbsp;<department href="http://www.sogou.com/docs/terms.htm?v=1" target="_blank" class="g">免责声明</department>&nbsp;-&nbsp;<department href="http://fankui.help.sogou.com/index.php/web/web/index/type/4" target="_blank" class="g">意见反馈及投诉</department>&nbsp;-&nbsp;<department href="http://corp.sogou.com/private.html" target="_blank" class="g" uigs-id="footer_private">隐私政策</department><br><span class="g">药品医疗器械网络信息服务备案：（京）网药械信息备字（2021）第00047号</span>&nbsp;/&nbsp;<span class="g">互联网药品信息服务资格证书(非经营性)：(京)-非经营性-2018-0311</span><br>©&nbsp;2004-2022&nbsp;Sogou.com&nbsp;/&nbsp;<department href="http://www.12377.cn" class="g" target="_blank">网上有害信息举报专区</department>&nbsp;/&nbsp;<span class="g">京网文(2019)6117-724号</span>&nbsp;/&nbsp;<department class="g" href="https://beian.miit.gov.cn/" target="_blank">京ICP证050897号</department>&nbsp;/&nbsp;<department class="g" href="https://beian.miit.gov.cn/" target="_blank">京ICP备11001839号-1</department>&nbsp;/&nbsp;<department href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11000002000025" class="ba" target="_blank">京公网安备11000002000025号</department></div>  <div class="fit-older"></div>  </div> <div class="kuozhan" id="QRcode-box" style="display:none"><department href="javascript:void(0);" id="miniQRcode"></department><span id="QRcode"></span></div><department href="javascript:void(0);" class="back-top" id="back-top"></department></div> <script>var SugPara, uigs_para, msBrowserName = navigator.userAgent.toLowerCase(),msIsSe = false,msIsMSearch = false, hasDoodle = false, queryinput = document.getElementById('query');</script><script>/*file=static/js/indexjs.js*/function indexjsInit(e,o,n,t,s,u,i){var r={puid:t,cards:s,cards_sw:u,uigs_cookie:"SUID,sct,SUV"};function c(){try{window.external.metasearch("make_connection","www.google.com.hk")}catch(e){}}uigs_para={uigs_productid:"webapp",type:"webindex_new",stype:e?"login":"nologin",scrnwi:screen.width,scrnhi:screen.height,uigs_pbtag:"A",uigs_cookie:"SUID,sct",protocol:"https:"==location.protocol.toLowerCase()?"https":"http"},e&&(uigs_para=Object.assign(uigs_para,r)),window.loginCardConfig={},SugPara={queryboxid:"search-box",enableSug:!0,sugType:"web",domain:"w.sugg.sogou.com",productId:"web",sugFormName:"sf",inputid:"query",submitId:"stb",suggestRid:"01015002",normalRid:"01019900",useParent:1,sugglocation:"index",showVr:!0,showHotwords:!0,suggAbtestObject:o},/se 2\.x/i.test(msBrowserName)&&(msIsSe=!0),/metasr/i.test(msBrowserName)&&(msIsMSearch=!0),queryinput&&msIsSe&&msIsMSearch&&(queryinput.addEventListener?(queryinput.addEventListener("keypress",c,!1),queryinput.addEventListener("keydown",c,!1)):queryinput.attachEvent?(queryinput.attachEvent("onkeypress",c),queryinput.attachEvent("onkeydown",c)):(queryinput.onkeypress=c,queryinput.onkeydown=c)),window.m_s_index=function(){var e=document.sf.query,o=Math.round(1e3*((new Date).getTime()+Math.random()));e.focus(),new RegExp("kw=([^&]+)").test(location.search)&&0==e.value.length&&(e.value=decodeURIComponent(RegExp.$1)),document.cookie.indexOf("SUV=")<0&&(document.cookie="SUV="+o+";path=/;expires=Sun, 29 July 2026 00:00:00 UTC;domain="+function(){var e=document.domain;return e.indexOf("sogou.com")==e.length-9?".sogou.com":e.indexOf("soso.com")==e.length-8?".soso.com":-1!=e.indexOf("sogo.com")?".sogo.com":void 0}()),n&&((new Image).src="//pb6.sogou.com/v6")},window.st=function(e,o,n,t){var s=document.sf.query,u=encodeURIComponent(s.value),i={news:"http://news.sogou.com/news?ie=utf8&query=",web:"web?ie=utf8&query=",weixin:"http://weixin.sogou.com/weixin?type=2&ie=utf8&query=",zhihu:"http://zhihu.sogou.com/zhihu?ie=utf8&query=",pic:"http://pic.sogou.com/pics?ie=utf8&query=",video:"https://v.sogou.com/v?ie=utf8&query=",myingyi:"https://www.sogou.com/web?m2web=mingyi.sogou.com&ie=utf8&query=",overseas:"http://english.sogou.com?b_o_e=1&ie=utf8&fr=pcweb_index_nav&query=",scholar:"http://scholar.sogou.com?ie=utf8&fr=common_index_nav&query=",fanyi:"http://fanyi.sogou.com/?fr=common_index_nav_pc&ie=utf8&keyword=",wenwen:"http://wenwen.sogou.com/s/?ch=websearch&w=",hanyu:"https://hanyu.sogou.com/?query=",science:"https://baike.sogou.com/kexue/home.htm?query="},r=i[n]||e.href;function c(e){return-1<e.indexOf("?")?"&":"?"}s&&""!==s.value&&(["hanyu"].includes(n)?r=r.match(/.*(?=\?query\=)/)[0]+{hanyu:{index:"",result:"result"}}[n].result+"?query="+u:i[n]?r=i[n]+u:0<r.indexOf("kw=")?r=r.replace(new RegExp("kw=[^&$]*"),"kw="+u):r+=c(r)+"kw="+u),o&&(r+=c(r)+"p="+o),t&&0<t.length&&(r+="#"+t),!s||""!=s.value||"wenwen"!=n&&"science"!=n||(r=e.href),e.href=r},window.cid=function(e,o){var n=document.sf.query,t=encodeURIComponent(n.value);t?"web2ww"===o?e.href+="s/?cid=web2ww&w="+t:"web2bk"===o&&(e.href+="Search.e?sp=S"+t+"&cid=web2bk"):e.href+="?cid="+o},window.m_s_index()}indexjsInit(false, {"suggestHistoryStrategy1":"","suggestHistoryStrategy2":"0|1|2|3|4|5|6|7|8","suggHistoryAbtest":""}, true, 'invaliduser', '', '');</script><script src="//dlweb.sogoucdn.com/pcsearch/web/index/js/suggbase_b9937f7.js"></script>  <script src="//dlweb.sogoucdn.com/pcsearch/js/common/widget/index_login_b1cc5cb.js"></script><script src="//account.sogou.com/static/api/passport-async.js"></script><script type="text/javascript" src="https://account.sogou.com/static/api/sogou.js?t=2017110901" async=""></script>  <script src="//dlweb.sogoucdn.com/pcsearch/web/index/js/searchbase_453304b.js"></script>   <script defer="defer" async="" type="text/javascript" src="//dlweb.sogoucdn.com/barrier_free/pc/wzaV15/aria.js?appid=c4d5562ec7daa12a5a351cbe1a292da1" charset="utf-8" id="ariascripts"></script><script charset="gb2312" src="/suggnew/hotwords?v=1651332524838"></script></body></html>


# 截图
"""
使用场景 ： 结合 allure 报告
记录关键页面
    断言页面
    重要的业务场景页面
    容易出错的页面
异常情况下的截图
写到 allure 测试报告中
"""

# page_source记录  ： 主要是用来调式
"""
使用 page_source 属性获取页面源码
在调试过程中，如果有找不到元素的错误，可以保存当时的 page_source 调式代码
后面会结合实际场景
在报错行前面添加保存 page_souce 的操作
with open('record.html','w',encoding='utf-8') as f:
    f.write(self.driver.page_source)
"""
